<template>
    <div>
        <!-- 共用头部组件 -->
        <common-header
            headerTitle="待入账"
            :hasBack="true"
            :hasHome="true"
        ></common-header>
        <!-- 共用头部组件 -->

        <!-- 共用页面滚动组件 -->
        <common-scroll
            :scrollStyle="scrollStyle"
            :isLoadMore="true"
            :data="logs"
            @pullup="loadMore"
        >

            <div
                class="logs-empty-tips"
                v-if="logs.length == 0"
            >{{emptyTips}}</div>

            <!-- 明细列表组件 -->
            <div
                class="detail-item"
                v-for="(item,index) of logs"
                :key="index"
            >
                <div class="item">
                    <span class="item-name">{{item.remark}}</span>
                </div>
                <div class="item">
                    <span class="item-date">{{item.add_time}}</span>
                    <span class="item-transaction-money"><span v-if="item.change>0">+</span>{{item.change | currency}}</span>
                </div>
            </div>
            <!-- 明细列表组件 -->

        </common-scroll>
        <!-- 共用页面滚动组件 -->
    </div>
</template>

<script>
import CommonHeader from '@/components/Header'
import CommonScroll from '@/components/Scroll'
export default {
    name: 'WatingAccount',
    components: {
        CommonHeader,
        CommonScroll
    },
    data() {
        return {
            scrollStyle: {
                top: '1.11rem',
                left: '0',
                right: '0',
                bottom: '0'
            },
            logs: [],
            emptyTips: '正在全力加载中...',
            nowPage: 1,
            totalPage: 1,
            isLoading: false
        }
    },
    mounted() {
        this.getUserLogs()
    },
    methods: {
        getUserLogs() {
            this.isLoading = true
            let postData = this.qs.stringify({
                received: 0,
                page_size: 20,
                page: this.nowPage
            })
            this.axios.post('/api/user/money/logs.json', postData).then(res => {
                const data = res.data
                if (data.status == 1) {
                    if (data.data.list.length == 0) {
                        this.emptyTips = '暂无数据'
                    }
                    this.logs = this.logs.concat(data.data.list)
                    this.totalPage = Math.ceil(data.data.page_info.total / 20)
                    this.nowPage++
                    this.isLoading = false
                } else {
                    this.commonDialog.alert('提示', data.msg)
                }
            })
        },
        loadMore() {
            if (this.totalPage >= this.nowPage && this.isLoading == false) {
                this.getUserLogs()
            }
        }
    },
    filters: {
        currency(value) {
            return parseFloat(value / 100).toFixed(2)
        }
    }
}
</script>

<style lang="stylus" scoped>
.logs-empty-tips
    height 2rem
    line-height 2rem
    text-align center
    font-size 0.33rem
    color #999
.detail-item
    padding 0.44rem 0.37rem
    background #fff
    border-bottom 1px solid #eee
    .item
        display flex
        align-items center
        justify-content space-between
        margin-bottom 0.18rem
        .item-name
            font-size 0.38rem
            color #666
            line-height 1.3
        .item-date
            font-size 0.33rem
            color #999
        .item-account-money
            font-size 0.33rem
            color #666
        .item-transaction-money
            font-size 0.33rem
            color #d7463c
    .item:last-child
        margin 0
.detail-item:last-child
    border none
</style>


